/*
 * Created by Federico Pisarello - SisDev Software (c) 2013 - fpisarello@sisdevsoft.com
 */

var actionForm = 'loginAction.php';

function loginValidacion() {
	if($("#userName").val()==''){
		$('#userName').effect("shake",{distance:5},'fast');
		$_showMessage('ALERT', 'ALERTA', 'Debe ingresar un correo electr&oacute;nico.');
		return false;
	}else if($("#password").val()==''){
		$_showMessage('ALERT', 'ALERTA', 'Debe ingresar su contrase&ntilde;a.');
		$('#password').effect("shake",{distance:5},'fast');
		return false;
	}else{
		
		$.ajax({
	        type: 'POST',
	        url: actionForm,
	        data: {'accion' : 'validaUsuario', userName: $('#userName').val(), password: $('#password').val()},
			dataType: 'json',
	        success: function(jsonObj)
	                    {
							if(jsonObj.status === 'GRANT') {
								window.location.href= 'main.php';
							}
							else {
								$_showMessage('ERR', 'ERROR', jsonObj.msg);
								$('#userName,#password').effect("shake",{distance:5},'fast');
							}
	                    }
	    });
	}
	return false;
}


function $_sendMailContact()
{
	if($('#name').val() === ''){ 
		$_showMessage('ALERT', 'ALERTA', strMenssageErrorMandatoryFields);
		$('#name').effect("shake",{distance:5},'fast');
		return false;
	}
	
	if($('#email').val() === ''){
		$_showMessage('ALERT', 'ALERTA', strMenssageErrorMandatoryFields);
		$('#email').effect("shake",{distance:5},'fast');
		return false;
	}
	
	if($('#phone').val() === ''){
		$_showMessage('ALERT', 'ALERTA', strMenssageErrorMandatoryFields);
		$('#phone').effect("shake",{distance:5},'fast');
		return false;
	}
	
	if($('#subject').val() === ''){
		$_showMessage('ALERT', 'ALERTA', strMenssageErrorMandatoryFields);
		$('#subject').effect("shake",{distance:5},'fast');
		return false;
	}
	
	if($('#message').val() === ''){
		$_showMessage('ALERT', 'ALERTA', strMenssageErrorMandatoryFields);
		$('#message').effect("shake",{distance:5},'fast');
		return false;
	}
	
	$("#initLoaderContact").show();
	
	//Disabled Button
	$("#butSendContact").attr('disabled','disabled');
	
	paramData = 'accion=sendMailContact&' + $('#frmContacto').serialize();
	
	$.ajax({
			type: 'POST',
			url: actionForm,
			data: {'accion' : 'sendMailContact', name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), subject: $('#subject').val(), message: $('#message').val()},
			dataType: 'json',
			success: function(jsonObj)
								{
									if(jsonObj.status === 'OK'){
										$_showMessage('OK', jsonObj.status, jsonObj.msg);
										$('#name').val('');
										$('#email').val('');
										$('#phone').val('');
										$('#subject').val('');
										$('#message').val('');
										
										$_showMessage('OK', jsonObj.status, jsonObj.msg);
									}
									else
										$_showMessage('ERR', jsonObj.status, jsonObj.msg);
									
									$("#butSendContact").removeAttr('disabled');
									$("#initLoaderContact").hide();
								}
			});
}

function $_changeLanguage(slanguage)
{
	$('#selLanguage').val(slanguage);
	$('#frmWebPage').submit();
}